package com.dongrj.framework.starter.sms;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

public class SmsActiveCondition implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(ConditionalOnSmsActive.class.getName());
        String value = annotationAttributes != null ? (String) annotationAttributes.get("active") : "";
        String smsActive = context.getEnvironment().getProperty("sms.active");
        return smsActive == null || smsActive.isEmpty() || value.equals(smsActive);
    }
}